Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Dec 25, 2025

Fixes #464

BigDecimal('1e+10000000000').add(1, 10) allocates GB of memory.
BigDecimal('1e+10000000000').add(BigDecimal('0.1e+9999999990'), 10) will give the same rounding result with less memory allocation and computation time.

Also fixes this NoMemoryError

x = BigDecimal('1e1000000000000000')
x + 0
#<NoMemoryError: failed to allocate memory>

@tompng tompng added the bug label Dec 28, 2025
…huge difference

BigDecimal('1e+10000000000').add(1, 10) allocates GB of memory.
BigDecimal('1e+10000000000').add(BigDecimal('0.1e+9999999990'), 10) will give the same rounding result with less memory allocation and computation time.
@tompng tompng force-pushed the addsub_huge_exponent_diff branch from 97be589 to 0649946 Compare December 28, 2025 13:28
@tompng tompng merged commit 27f0242 into ruby:master Dec 28, 2025
87 of 89 checks passed
@tompng tompng deleted the addsub_huge_exponent_diff branch December 28, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding/subtracting bigdecimals with huge differences in exponents hangs

1 participant